void Clear()

robot_2Generated
code_blocksInput

Description

The Clear method of the NetList<T> class is used to remove all elements from the list. This method is sealed, meaning it cannot be overridden in derived classes. It is a virtual method, allowing it to be invoked on instances of derived classes. The method is public and non-static, meaning it can be called on an instance of NetList<T>.

This method is particularly useful in scenarios where you need to reset the list to an empty state, ensuring that all elements are removed efficiently. The Clear method is similar to the Clear method in System.Collections.Generic.List<T>, and it inherits its behavior from there.

Usage

To use the Clear method, simply call it on an instance of NetList<T>. This will remove all elements from the list, leaving it empty. Note that this operation will also trigger any network synchronization mechanisms if the list is being used in a networked context with the SyncAttribute or HostSyncAttribute.

Example usage:

public class MyComponent : Component
{
    [Sync] public NetList<int> MyIntegerList { get; set; } = new();

    public void ResetList()
    {
        if ( IsProxy ) return;
        MyIntegerList.Clear();
    }
}

Example

public class MyComponent : Component
{
    [Sync] public NetList<int> MyIntegerList { get; set; } = new();

    public void ResetList()
    {
        if ( IsProxy ) return;
        MyIntegerList.Clear();
    }
}